//三个原生模块
const http=require("http");
const fs=require("fs");
const path=require("path");

//base64比较适合小图标
http.createServer((req,res)=>{
    let filePath=path.join(__dirname,"aaa.jpg");
    let fileContent=fs.readFileSync(filePath);//得到图片的buffer数据
    fileContent=fileContent.toString("base64");//得到图片的base64数据
    let imgSrc='data:image/jpg;base64,'+fileContent
    let imgStr="<img src='"+imgSrc+"'/>";

    let htmlStr="<!DOCTYPE html>"+
        "<html>"+
        "<head></head>"+
        "<body>"+
        "<h1>这是一个网页</h1>"+imgStr+
        "</body>"+
        "</html>";
    res.writeHead(200,{"Content-Type":"text/html;charset=utf8"})
    res.end(htmlStr)
}).listen(3000);

console.log("server is listening 3000")